package com.foreveross.taskservice.core.domain.task;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.openkoala.koala.commons.domain.KoalaIDEntity;

import com.foreveross.taskservice.core.domain.task.assign.AssignDayType;
/**
 * 指定抓取间隔时间的任务模版
 */
@javax.persistence.Table(name = "CRAWL_TASK_TEMPLATE_ASSIGNDAY")
@javax.persistence.Entity
public class TaskTemplateAssignDayEntity extends KoalaIDEntity{
	private static final long serialVersionUID = -8919716605426792555L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id")
	private Long id;
	/**
	 * 对应的模版
	 */
	@ManyToOne
	@JoinColumn(name="TEMPLATE_ID",referencedColumnName="ID")
	private TaskTemplateEntity template;
	/**
	 * 起飞的时间类型，1指定日期区间，2未来固定日期天数，3 未来每周周几，4每月第几天，5每季第几天
	 */
	@Column(name="DAY_TYPE")
	private Integer dayType = 2;
	/**
	 * 指定的距离当天的起飞时间间隔,根据上面的类型不同含义也不同，为１指定日期区间时，该值没有作用，为２未来天数，该值表示未来第几天
	 * 为３周几，则表示周几.....
	 */
	@Column(name="ASSIGN_FLIGHT_DAY")
	private Integer assignFlightDay;
	/**
	 * 指定的距离起飞时间的回程时间间隔
	 */
	@Column(name="ASSIGN_ROUND_DAY")
	private Integer assignRoundDay;
	/**
	 * 固定日期开始
	 */
	@Column(name="START_DATE")
	private Date startDate;
	/**
	 * 固定日期结束
	 */
	@Column(name="END_DATE")
	private Date endDate;
	/**
	 * 未来周期，对应于上面的dayType，如果是周几，代表未来连续的多少周周几，如果是月，代表未来连续多少个月的月第几天
	 */
	@Column(name="FUTURE_CYCLE")
	private Integer futureCycle = 0;
	
	public TaskTemplateEntity getTemplate() {
		return template;
	}
	public void setTemplate(TaskTemplateEntity template) {
		this.template = template;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	public Integer getAssignFlightDay() {
		return assignFlightDay;
	}
	public void setAssignFlightDay(Integer assignFlightDay) {
		this.assignFlightDay = assignFlightDay;
	}
	public Integer getAssignRoundDay() {
		return assignRoundDay;
	}
	public void setAssignRoundDay(Integer assignRoundDay) {
		this.assignRoundDay = assignRoundDay;
	}
	
	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	
	public Integer getDayType() {
		return dayType;
	}
	public void setDayType(Integer dayType) {
		this.dayType = dayType;
	}

	
	public Integer getFutureCycle() {
		return futureCycle;
	}
	public void setFutureCycle(Integer futureCycle) {
		this.futureCycle = futureCycle;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("TaskTemplateAssignDayEntity [id=");
		builder.append(id);
		builder.append(", dayType=");
		builder.append(dayType);
		builder.append(", assignFlightDay=");
		builder.append(assignFlightDay);
		builder.append(", assignRoundDay=");
		builder.append(assignRoundDay);
		builder.append(", startDate=");
		builder.append(startDate);
		builder.append(", endDate=");
		builder.append(endDate);
		builder.append(", futureCycle=");
		builder.append(futureCycle);
		builder.append("]");
		return builder.toString();
	}
	@Override
	public String[] businessKeys() {
		return new String[]{getClass().getName()+id};
	}
	
	public AssignDayType getAssignDayType(){
		return AssignDayType.convert(this.getDayType());
	}
	
}
